package pkg

import (
	"io"
	"log"
	"net/http"

	"github.com/aliyun/aliyun-oss-go-sdk/oss"
)

//oss云上传(实现加水印功能)

func Upload(filename string) {
	client, err := oss.New("https://oss-cn-hangzhou.aliyuncs.com", "LTAI5tQ3WGa4ZU8uW6yqVHRC", "KIkjJ03kcu5XixmCumclaJGZMzbjt2")
	if err != nil {
		log.Fatalf("Failed to create OSS client: %v", err)
	}

	// 填写存储空间名称，例如examplebucket。
	bucketName := "yz6669" // 请替换为实际的Bucket名称
	bucket, err := client.Bucket(bucketName)
	if err != nil {
		log.Fatalf("Failed to get bucket: %v", err)
	}

	// 填写Object的完整路径，例如exampledir/exampleobject.txt。
	objectName := "img/watermark" + filename

	// 指定待上传的网络流。
	resp, err := http.Get("https://yz6669.oss-cn-hangzhou.aliyuncs.com/img/naruto.jpg?x-oss-process=image/watermark,text_SGVsbG8gV29ybGQ")
	if err != nil {
		log.Fatalf("Failed to fetch URL: %v", err)
	}
	defer resp.Body.Close()

	// 将网络流上传至OSS。
	err = bucket.PutObject(objectName, io.Reader(resp.Body))
	if err != nil {
		log.Fatalf("Failed to put object: %v", err)
	}

	log.Println("File uploaded successfully.")
}
